<?php
class Telequestion extends Controller {

    private $aPost;
    private $aUser;

    function Telequestion() {

        parent::Controller();
        $this->load->model('model_telequestion');

        //verificare sesiune
        if (!$this->usersession->userLoggedIn()) {
            $aResponse = array("error" => true, "description" => "Sesiunea a expirat", "type" => "nosession");
            die(json_encode($aResponse));
        }
        copyPost($this->aPost);
        $this->aUser = $this->usersession->currentUser();
    }

    /**
     * Functie care aduce datele in grid
     */
    function getData() {
        echo json_encode($this->model_telequestion->getData($_POST));
    }

     /**
     * Functie care aduce datele in grid
     */
    function getQuestionAnswer() {
        echo json_encode($this->model_telequestion->getQuestionAnswer($_POST));
    }

    /**
     * Functie de editare / inserare element
     * @return string json
     */
    function operation() {

        $bResponse = $this->model_telequestion->operation($this->aPost);

        if ($bResponse === TRUE) {
            $aResponse = array("error" => false, "success" => true, "description" => "Datele au fost salvate");
        }
        else {
            $aResponse = array("error" => true, "description" => $bResponse, "type" => "Validare");
        }
        echo  json_encode($aResponse);
    }

     /**
     * Functie de editare / inserare element
     * @return string json
     */
    function operationAnswer() {

        $bResponse = $this->model_telequestion->operationAnswer($this->aPost);

        if ($bResponse === TRUE) {
            $aResponse = array("error" => false, "success" => true, "description" => "Datele au fost salvate");
        }
        else {
            $aResponse = array("error" => true, "description" => $bResponse, "type" => "Validare");
        }
        echo  json_encode($aResponse);
    }

    /**
     * Functie care aduce datele despre unei inregistrari
     * @return string json
     */
    function getRecord() {
        $aResult = $this->model_telequestion->getRecord($this->aPost);
        echo json_encode(array("error" => false, "data" => $aResult));
    }

    /**
     * Functie care aduce datele despre unei inregistrari
     * @return string json
     */
    function getAnswer() {
        $aResult = $this->model_telequestion->getAnswer($this->aPost);
        echo json_encode(array("error" => false, "data" => $aResult));
    }


}
